package Thread.Thread_Pool;

import java.util.concurrent.*;

/**
 * Executors 创建线程池的四种方式的简单应用
 */
public class test {
    public static void main(String[] args) {
        ExecutorService pool1 = Executors.newFixedThreadPool(10);
        pool1.submit(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println(Thread.currentThread().getName() + "hello~" + i);
                }
            }
        });
        ExecutorService pool2 = Executors.newCachedThreadPool();
        pool2.submit(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println(Thread.currentThread().getName() + "hello~" + i);
                }
            }
        });
        ExecutorService pool3 = Executors.newSingleThreadExecutor();
        pool3.submit(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 5; i++) {
                    System.out.println(Thread.currentThread().getName() + "hello~" + i);
                }
            }
        });
        ScheduledExecutorService pool4=Executors.newScheduledThreadPool(10);
        pool4.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"3秒后执行次任务~~~");
            }
        },3, TimeUnit.SECONDS);
    }
}